﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using weikebuluo.DAL;
using weikebuluo.Common;
using weikebuluo.Model;

namespace weikeweixin.web.pcweb
{
    public partial class index : System.Web.UI.Page
    {
        a_user_dal userdal = new a_user_dal();
        a_user_model usermodel = new a_user_model();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)                    //当页面首次加载时
            {
                Session["user_name"] = null;    //清除用户登录
            }
            switch (Request.Form["action"]) { 
                case "login":
                    login();
                    break;
            }
        }

        private void login() {
            DataTable dtuser = userdal.GetList("user_name='" + Request.Form["username"] + "' and user_psw='" +MD5Provider.GetMd5(Request.Form["password"]) + "'").Tables[0];
            if (dtuser.Rows.Count > 0)
            {
                Session["user_name"] = dtuser.Rows[0]["user_name"];

                int lever = Convert.ToInt32(dtuser.Rows[0]["user_level"]);

                if (lever == 1000)
                {
                    Response.Write("<script Language=\"Javascript\">top.location=\"/web/admin/main/root_manager.aspx\";");
                    Response.Write("</script>");
                }
                else
                {
                Response.Write("<script Language=\"Javascript\">top.location=\"/web/admin/main/index.aspx\";");
                Response.Write("</script>");
                }
            }
            else {
                Response.Write("<script Language=\"Javascript\">alert(\"用户名或密码错误！\");");
                Response.Write("</script>");
                Response.Write("<script Language=\"Javascript\">top.location=\"/web/pcweb/index.aspx\";");
                Response.Write("</script>");
            }
            Response.End();
        }
    }
}